# 导入所需要的库
import cv2
import numpy as np
import os
import matplotlib.pyplot as plt 
# 定义保存图片函数
# image:要保存的图片名字
# addr；图片地址与相片名字的前部分
# num: 相片，名字的后缀。int 类型
def save_image(image,addr,num):
	address = addr + str(num)+ '.jpg'
	cv2.imwrite(address,image)


  
# 读取视频文件
video_file = "test_porn_sj.mp4"

videoCapture = cv2.VideoCapture(video_file)
# 通过摄像头的方式
fps = videoCapture.get(cv2.CAP_PROP_FPS)
print(fps)
# 读帧
# videoCapture.set(cv2.CAP_PROP_POS_FRAMES,500)
success, frame = videoCapture.read()


# frame = cv2.imread('./t/s2.jpg')

# save_image(frame,'./t/','s00')
# plt.imshow(frame)
# plt.show()
i = 0
timeF = 5
j=0
while success :
	
	if (i % timeF == 0):
		j = j + 1
		# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        # # frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
		save_image(frame,'./demo_porn/',j)
		print('save image:',i+1)
	i = i + 1
	success, frame = videoCapture.read()






